﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using ZF.BLL.Page;
using GCELibrary.Current;
namespace ZF.WS.Admin.sys
{
    public partial class SysConfig :MMPage
    {
        public override ModuleType Module
        {
            get { return ModuleType.SysSetup; }
            protected set
            {
                base.Module = value;
            }
        }


        [PageArgument(Key = "key", DefaultValue=null)]
        public string Key { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (var control in dtMenu.Controls)
            {
                if (control is IButtonControl)
                {
                    var bc = (IButtonControl)control;
                    bc.Click += MenuClick;
                }
            }
            if (!IsPostBack)
            {
                if (Key != null)
                {
                    foreach (Control c in dtMenu.Controls)
                    {
                        if (c is IButtonControl && ((IButtonControl)c).CommandArgument.EqIgnoreCase(Key))
                        {
                            MenuClick(c, null);
                        }
                    }
                }
            }
            else
            {
                foreach (Control c in dtMenu.Controls)
                {
                    if (c is IButtonControl)
                    {
                        ((WebControl)c).Attributes["class"]= ((WebControl)c).Attributes["class"].EmptyString("").Replace("active","");
                    }
                }
            }
           
        }
        public void MenuClick(object sender, EventArgs e)
        {
            var bt = (IButtonControl)sender;
            var id = "v" + bt.CommandArgument;
            var view = (View)this.MultiView1.FindControl(id);
            ((WebControl)sender).Attributes["class"] = "active";
            this.MultiView1.SetActiveView(view);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            var view = this.MultiView1.GetActiveView();
            foreach (var control in view.Controls)
            {
                if (control is _uc)
                {
                    var uc = (_uc)control;
                    uc.InitControls();
                }
            }
        }
    }
}
